<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      class="form-search"
      label-width="100px">
      <el-form-item :label="$t('SMSRp.phone')"
        prop="phone">
        <el-input v-model="queryParams.phone"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('SMSRp.smsCode')"
        prop="smsCode">
        <el-input v-model="queryParams.smsCode"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('SMSRp.status')"
        prop="status">
        <el-select v-model="queryParams.status"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.sms_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('SMSRp.dateRange')">
        <el-date-picker v-model="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          :clearable="false"
          range-separator="-"
          :start-placeholder="$t('common.startDate')"
          :end-placeholder="$t('common.endDate')"
          style="width: 240px"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">{{$t('common.search')}}</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">{{$t('common.reset')}}</el-button>
      </el-form-item>
    </el-form>

    <div class="section-box">

      <el-table v-loading="loading"
        :data="dataList">
        <!-- <el-table-column type="selection"
          width="55"
          align="center" /> -->
        <el-table-column :label="$t('SMSRp.phone')"
          align="center"
          prop="phone"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('SMSRp.smsCode')"
          align="center"
          prop="smsCode"
          min-width="120" />
        <el-table-column :label="$t('SMSRp.smsContent')"
          align="center"
          prop="smsContent"
          :show-overflow-tooltip="true"
          min-width="200" />
        <el-table-column :label="$t('SMSRp.status')"
          align="center"
          min-width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sms_status"
              :value="scope.row.status" />
          </template>
        </el-table-column>
        <!-- <el-table-column :label="$t('common.createBy')"
          align="center"
          prop="createBy"
          min-width="140"
          show-overflow-tooltip /> -->
        <el-table-column :label="$t('common.createTime')"
          align="center"
          prop="createTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column :label="$t('common.updateBy')"
          align="center"
          prop="updateBy"
          min-width="140"
          show-overflow-tooltip /> -->
        <el-table-column :label="$t('common.updateTime')"
          align="center"
          prop="updateTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </div>
</template>

<script>
import {
  SMSReceptionList,
} from "@/api/OTP/SMSReception.js";
import { dateFormat } from '@/utils/util.js'

export default {
  name: "U",
  dicts: ["sms_status"],
  data () {
    return {
      // 遮罩层
      loading: true,

      // 总条数
      total: 0,
      // 角色表格数据
      dataList: [],

      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone: null,
        smsCode: null,
        status: null,
        startDate: null,
        endDate: null,
      },

    };
  },
  watch: {
    dateRange (val) {
      if (val) {
        this.queryParams.startDate = val[0]
        this.queryParams.endDate = val[1]
      } else {
        this.queryParams.startDate = null
        this.queryParams.endDate = null
      }
    },
  },
  created () {
    this.dateRange = [dateFormat(new Date(), "yyyy-MM-dd"), dateFormat(new Date(), "yyyy-MM-dd")]
    this.queryParams.startDate = dateFormat(new Date(), "yyyy-MM-dd")
    this.queryParams.endDate = dateFormat(new Date(), "yyyy-MM-dd")
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList () {
      this.loading = true;
      SMSReceptionList(this.queryParams).then(
        (response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.dateRange = [dateFormat(new Date(), "yyyy-MM-dd"), dateFormat(new Date(), "yyyy-MM-dd")]
      this.queryParams.startDate = dateFormat(new Date(), "yyyy-MM-dd")
      this.queryParams.endDate = dateFormat(new Date(), "yyyy-MM-dd")
      this.handleQuery();
    },
  },
};
</script>
